
#include "choosesence.h"

choosesence::choosesence(QWidget *parent)
    : QMainWindow{parent},pls(nullptr)
{
    this->setFixedSize(320,588);
    this->setWindowIcon(QPixmap(":/new/coifilp/res/Coin0001.png"));
    this->setWindowTitle("choose level");
    QMenuBar* bar=menuBar();
    setMenuBar(bar);
    QMenu* me= bar->addMenu("开始");
    QAction* qq=me->addAction("退出");
    connect(qq,&QAction::triggered,this,[=](){
        this->close();
    });
    QSoundEffect* qsc=new QSoundEffect(this);
    qsc->setSource(QUrl::fromLocalFile(":/new/coifilp/res/BackButtonSound.wav"));
    QSoundEffect* qsb=new QSoundEffect(this);
    qsb->setSource(QUrl::fromLocalFile(":/new/coifilp/res/BackButtonSound.wav"));
    myPushButton* mpbk=new myPushButton(":/new/coifilp/res/BackButton.png",":/new/coifilp/res/BackButtonSelected.png");
    mpbk->setParent(this);
    mpbk->move(this->width()-mpbk->width(),this->height()-mpbk->height());
    connect(mpbk,&myPushButton::clicked,mpbk,[=](){
        qsb->play();
        QTimer::singleShot(500,this,[=](){
emit this->backtomain();
        });
    });
    for(int i=0;i<20;i++){
        myPushButton* levelbtn=new myPushButton(":/new/coifilp/res/LevelIcon.png");
        levelbtn->setParent(this);
        levelbtn->move(this->width()*3/31+(i%4)*this->width()*7/31,this->height()*0.3+(levelbtn->height())*(i/4));
        connect(levelbtn,&myPushButton::clicked,this,[=](){
            qsc->play();
            if(pls==nullptr){
                this->hide();
                pls=new palysecne(i+1);
                pls->setGeometry(this->geometry());
                connect(pls,&palysecne::bktochoose,this,[=](){
                    this->setGeometry(pls->geometry());
                    this->show();
                    delete pls;
                    pls=nullptr;
                });
                pls->show();
            }
            });
        QLabel* qlbl=new QLabel(this);
        qlbl->setText(QString::number(i+1));
        qlbl->setFixedSize(levelbtn->size());
        QFont ft;ft.setPointSize(14);
        qlbl->setFont(ft);
        qlbl->setAlignment(Qt::AlignCenter);
        qlbl->move(this->width()*3/31+(i%4)*this->width()*7/31,this->height()*0.3+(levelbtn->height())*(i/4));
        qlbl->setAttribute(Qt::WA_TransparentForMouseEvents);
    }


}

void choosesence::paintEvent(QPaintEvent *event)
{
    QPainter* pq=new QPainter(this);
    QPixmap pix(":/new/coifilp/res/OtherSceneBg.png");
    pq->drawPixmap(0,0,this->width(),this->height(),pix);
    pix.load(":/new/coifilp/res/Title.png");
    //    pixmap = pixmap.scaled();
    pq->drawPixmap((this->width()-pix.width())*0.5,this->height()*0.07,pix);
    pq->end();
}

